package com.clas.liu.myapplication.network;

import android.support.annotation.NonNull;
import android.support.v4.util.ArrayMap;
import android.util.Log;

import com.clas.liu.myapplication.model.entity.info.Info;
import com.clas.liu.myapplication.model.entity.notice.Notice;

import okhttp3.Callback;

/**
 * 网络接口
 * Created by liu on 2019/2/25.
 */

public class NetworkInterfaces {

    private static final String SERVER_HOST = "http://192.168.253.1:8081/";


    private static final String GETUSER = "main/getUser";
    private static final String LOGIN = "login/login";
    private static final String PHONE_IS_EXITED = "login/phoneIsExited";
    private static final String REGISTER = "login/register";
    private static final String EDIT_USER = "login/editUser";
    private static final String EDIT_PASSWORD = "login/editPassword";

    private static final String GET_BANNER = "home/getBanner";
    private static final String GET_HEADS = "home/getHeads";

    private static final String GET_INFO = "square/getInfo";
    private static final String REPORT_INFO = "square/reportInfo";
    private static final String GET_USER_INFO = "user/getUserInfo";
    private static final String DELETE_INFO = "user/deleteInfo";
    private static final String SETTLED_INFO = "user/settledInfo";
    private static final String JUBAO_USER = "user/jubaoUser";

    private static final String ADD_INFO = "edit/addInfo";
    private static final String EDIT_INFO = "edit/editInfo";

    private static final String GET_USER_BY_ID = "user/getUserById";

    private static final String GET_INFO_FOR_CATEGORY = "category/getInfoByType";
    private static final String GET_HOT_KEYS = "search/getHotKeys";
    private static final String GET_SEARCH_INFO= "search/searchInfo";
    private static final String GET_SEARCH_USER = "search/searchUser";
    private static final String GET_NOTICES = "notice/getNotices";
    private static final String GET_NOTICE_COUNT = "notice/getNoticesTotal";

    private static final String POST_NOTICE = "administrator/postNotice";
    private static final String GET_REPORTED_USER = "administrator/getInfos";
    private static final String BAN_USER = "administrator/banUser";
    private static final String CANCEL_REPORTED = "administrator/cancel";
    private static final String GET_REPORTED_INFO= "administrator/getReportedInfo";
    private static final String DELETE_REPORTED_INFO= "administrator/deleteInfo";
    private static final String CANCEL_REPORTED_INFO= "administrator/cancelInfo";
    private static final String GET_BANDED_USER= "administrator/getBandedUser";
    private static final String CANCEL_BANDED= "administrator/cancelBanded";


    public void getUser(@NonNull Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("phone", "18281579662");
        new NetworkRequest(businessParam, SERVER_HOST + GETUSER, callback).sendRequest();
    }

    public void login(String phone, String password, @NonNull Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("phone", phone);
        businessParam.put("password", password);
        new NetworkRequest(businessParam, SERVER_HOST + LOGIN, callback).sendRequest();
    }

    public void phoneIsExited(String phone, @NonNull Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("phone", phone);
        new NetworkRequest(businessParam, SERVER_HOST + PHONE_IS_EXITED, callback).sendRequest();
    }

    public void register(String user, String pwd, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("user", user);
        businessParam.put("password", pwd);
        new NetworkRequest(businessParam, SERVER_HOST + REGISTER, callback).sendRequest();
    }

    public void editUser(String user, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("user", user);
        new NetworkRequest(businessParam, SERVER_HOST + EDIT_USER, callback).sendRequest();
    }

    public void editPassword(String phone, String pwd, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("phone", phone);
        businessParam.put("password", pwd);
        new NetworkRequest(businessParam, SERVER_HOST + EDIT_PASSWORD, callback).sendRequest();
    }

    public void getBanner(Callback callback) {
        new NetworkRequest(null, SERVER_HOST + GET_BANNER, callback).sendRequest();
    }

    public void getheads(Callback callback) {

        new NetworkRequest(null, SERVER_HOST + GET_HEADS, callback).sendRequest();
    }

    public void getInfo(int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_INFO, callback).sendRequest();
    }

    public void getUserInfo(int userId, int type, int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("user_id", String.valueOf(userId));
        businessParam.put("type", String.valueOf(type));
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_USER_INFO, callback).sendRequest();
    }

    public void addInfo(Info json, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("release_time", json.getRelease_time());
        businessParam.put("text", json.getText());
        businessParam.put("pic", json.getPic());
        businessParam.put("category", String.valueOf(json.getCategory()));
        businessParam.put("user_id", String.valueOf(json.getUser_id()));
        businessParam.put("key", json.getKey_word());
        new NetworkRequest(businessParam, SERVER_HOST + ADD_INFO, callback).sendRequest();
    }

    public void editInfo(int id, String relase_time, String text, String pic, String key_word, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("id", String.valueOf(id));
        Log.i("test", "editInfo: "+id);
        businessParam.put("release_time", relase_time);
        businessParam.put("text", text);
        businessParam.put("pic", pic);
        businessParam.put("key_word", key_word);
        new NetworkRequest(businessParam, SERVER_HOST + EDIT_INFO, callback).sendRequest();
    }

    public void getUserById(int userId, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("user_id", String.valueOf(userId));
        new NetworkRequest(businessParam, SERVER_HOST + GET_USER_BY_ID, callback).sendRequest();
    }

    public void getInfoForCategory(int category, int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("category", String.valueOf(category));
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_INFO_FOR_CATEGORY, callback).sendRequest();
    }

    public void getHotKeys(Callback callback) {
        new NetworkRequest(null, SERVER_HOST + GET_HOT_KEYS, callback).sendRequest();
    }

    public void searchInfo(String s, int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("key", s);
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_SEARCH_INFO, callback).sendRequest();
    }

    public void searchUser(String s, int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("key", s);
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_SEARCH_USER, callback).sendRequest();
    }

    public void getNotices(int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_NOTICES, callback).sendRequest();
    }

    public void getNoticeCount(Callback callback) {
        new NetworkRequest(null, SERVER_HOST + GET_NOTICE_COUNT, callback).sendRequest();
    }

    public void deleteInfo(int id, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("id", String.valueOf(id));
        new NetworkRequest(businessParam, SERVER_HOST + DELETE_INFO, callback).sendRequest();
    }

    public void settledInfo(int id, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("id", String.valueOf(id));
        new NetworkRequest(businessParam, SERVER_HOST + SETTLED_INFO, callback).sendRequest();
    }

    public void jubaoUser(int userId, String text, String pic,String releaseTime, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("user_id", String.valueOf(userId));
        businessParam.put("text",text);
        businessParam.put("pic", pic);
        businessParam.put("release_time", releaseTime);
        new NetworkRequest(businessParam, SERVER_HOST + JUBAO_USER, callback).sendRequest();
    }

    public void reportInfo(String info_id, String releaseTime, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("info_id", info_id);
        businessParam.put("release_time", releaseTime);
        new NetworkRequest(businessParam, SERVER_HOST + REPORT_INFO, callback).sendRequest();
    }

    public void postNotice(Notice notice, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("time", notice.getTime());
        businessParam.put("text", notice.getText());
        new NetworkRequest(businessParam, SERVER_HOST + POST_NOTICE, callback).sendRequest();
    }

    public void getReportedUser(int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_REPORTED_USER, callback).sendRequest();
    }

    public void banUser(int user_id, int id, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("user_id", String.valueOf(user_id));
        businessParam.put("id", String.valueOf(id));
        new NetworkRequest(businessParam, SERVER_HOST + BAN_USER, callback).sendRequest();
    }

    public void cancelReported(int id, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("id", String.valueOf(id));
        new NetworkRequest(businessParam, SERVER_HOST + CANCEL_REPORTED, callback).sendRequest();
    }

    public void getReportedInfo(int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_REPORTED_INFO, callback).sendRequest();
    }

    public void deleteReportedInfo(int info_id, int id, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("info_id", String.valueOf(info_id));
        businessParam.put("id", String.valueOf(id));
        new NetworkRequest(businessParam, SERVER_HOST + DELETE_REPORTED_INFO, callback).sendRequest();
    }

    public void cancelReportedInfo(int id, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("id", String.valueOf(id));
        new NetworkRequest(businessParam, SERVER_HOST + CANCEL_REPORTED_INFO, callback).sendRequest();
    }

    public void getBandedUser(int page_no, int page_size, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("page_no", String.valueOf(page_no));
        businessParam.put("page_size", String.valueOf(page_size));
        new NetworkRequest(businessParam, SERVER_HOST + GET_BANDED_USER, callback).sendRequest();
    }

    public void cancelBanded(int id, Callback callback) {
        ArrayMap<String, String> businessParam = new ArrayMap<>();
        businessParam.put("id", String.valueOf(id));
        new NetworkRequest(businessParam, SERVER_HOST + CANCEL_BANDED, callback).sendRequest();
    }
}
